<?php
/*
 * coding: utf-8
 * +-------------------------------------------------------------------
 * | KL库 - COOKIE模块
 * +-------------------------------------------------------------------
 * | Copyright (c) 2022-2099 KL库(https://www.fangheyun.xyz) All rights reserved.
 * +-------------------------------------------------------------------
 * | Author: 远易 <3431628590@qq.com>
 * +-------------------------------------------------------------------
 */

if(COOKIE_SWITCH){
    class COOKIE {
        public function create($key='', $value='', $time=0){
            if($key == ''){
                exit("ERROR: Key cannot be empty");
            }
            if($value == ''){
                exit("ERROR: Value cannot be empty");
            }
            if(!setcookie($key, $value, time()+$time)){
                return False;
            }
            return True;
        }
        public function set($key='', $value='', $time=0, $type=False){
            if($key == ''){
                exit("ERROR: Key cannot be empty");
            }
            if($value == ''){
                exit("ERROR: Value cannot be empty");
            }
            if(!$type){
                if(!setcookie($key, $value, time()+$time)){
                    return False;
                }
                return True;
            }
            if(!setcookie($key, $value, time()-$time)){
                return False;
            }
            return True;
        }
        public function cookie($key=''){
            if($key == ''){
                return $_COOKIE;
            }
            return $_COOKIE[$key];
        }
	}
}
?>